package com.oauth.components.client.ui.header;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.components.client.ui.CommonResources;

public class HeaderUI extends Composite {

	private static HeaderUiBinder uiBinder = GWT.create(HeaderUiBinder.class);

	interface HeaderUiBinder extends UiBinder<Widget, HeaderUI> {
	}

	private static final HeaderConstant constants = (HeaderConstant) GWT
			.create(HeaderConstant.class);

	@UiField
	Label userName;

	@UiField
	Label loadingLabel;

	@UiField
	VerticalPanel mainPanel;

	@UiField
	HorizontalPanel hPanel;

	@UiField
	HorizontalPanel rightPanel;

	@UiField
	HorizontalPanel loadingPanel;

	@UiField
	Anchor applicationLink;

	@UiField
	HTML newLink;

	public HeaderUI() {
		initWidget(uiBinder.createAndBindUi(this));
		userName.addStyleName(CommonResources.INSTANCE.css().bold());
		applicationLink.setText(constants.applicationLinkName());
		loadingLabel.setText(constants.loadingText());
		newLink.setHTML(constants.newHTML());
		hPanel.setCellHorizontalAlignment(rightPanel, VerticalPanel.ALIGN_RIGHT);

		loadingPanel.setCellHorizontalAlignment(loadingLabel, VerticalPanel.ALIGN_CENTER);

		loadingPanel.setCellHorizontalAlignment(loadingLabel, VerticalPanel.ALIGN_CENTER);

		loadingLabel.setVisible(false);

		loadingLabel.getElement().setId("loadingLabel");
	}

	public void setLoading(boolean pVisible) {
		loadingLabel.setVisible(pVisible);
	}

	public void setLoadingText(String pText) {
		loadingLabel.setText(pText);
	}

	public void setUserName(String pUserName) {
		userName.setText(pUserName);
	}

	public String getUserName() {
		return userName.getText();
	}
}
